<?php

class User extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('User_model');
    }

    public function index()
    {
        $name = $this->input->get('name');
        $status = $this->input->get('status'); //0未删除1已删除
        $search_type = $this->input->get('search_type'); //0默认查询1查关联
        $user_info = $this->User_model->get_user_info($name, $status);
        $sAccount = array_column($user_info, 'account');
        $account_info = $this->User_model->get_account_info($sAccount);
        if ($search_type == 1) {

            $ip_list = array_column($account_info, 'sLoginIP');
            $ip_info = array();
            if ($ip_list) {
                $ip_info = $this->User_model->get_account_info(null, $ip_list);
            }
            $ss_list = array_column($sAccount, 'sSSNo');
            $ss_info = array();
            if ($ss_list) {
                $ss_info = $this->User_model->get_account_info(null, null, $ss_list);
            }
            $sAccount = array_merge(array_column($account_info, 'sAccount'), array_column($ip_info, 'sAccount'), array_column($ss_info, 'sAccount'));
            $user_info = $this->User_model->get_user_info(null, 0, $sAccount);
            $account_info = $this->User_model->get_account_info($sAccount);
        }
        foreach ($user_info as &$user) {
            foreach ($account_info as $account) {
                if ($user['sAccount'] == $account['sAccount']) {
                    $user['ip'] = $account['sLoginIP'];
                    $user['ss'] = $account['sSSNo'];
                }
            }
        }
        $this->load->var('user_info', $user_info);
        $this->load->view('user/index');
    }

}